<?php
/**
 * name：登陆 Ajax
 * user：sa0
 * date：2021/2/6 08:32
 */
$account = Tool::gp('account');
$password = Tool::gp('password');
$check = Check::Input(['请输入账号' => $account, '请输入密码' => $password]);
if (!$check['check']) Tool::exit($check);
$db = Db::get();
$sql = 'select * from admin where account = ? and password = ?;';
$admin_info = $db->getRow($sql, [$account, md5(md5($password))]);
$check = Check::AdminInfo($admin_info);
if (!$check['check']) Tool::exit($check);
$token = md5(json_encode([
    'time' => time(),
    'admin' => $admin_info['id'],
    'rand' => rand(0, 999)
]));
Db2::u($db, 'admin', [
    'token' => $token,
    'update_time' => Tool::date()
], 'where id = ' . $admin_info['id']);
Db2::i($db, 'admin_login_log', [
    'admin_id' => $admin_info['id'],
    'token' => $token,
    'create_time' => Tool::date(),
    'create_ip' => Tool::ip()
]);
$de_token = Rc4::encode(json_encode([
    'token' => $token,
    'ip' => Tool::ip(),
    'time' => time()
]), Tool::ini('Rc4Key'), true);
Yo::echo([
    'token' => $de_token
]);
